<?php
	$this->breadcrumbs=array(
	//	'Contacts'=>array('index'),
		'Send',
	);
	if (!empty($newAddresses)) {
		Yii::app()->getClientScript()->registerScriptFile(Yii::app()->request->baseUrl . '/js/jquery-ui.min.js', CClientScript::POS_END);
		Yii::app()->getClientScript()->registerCssFile(Yii::app()->request->baseUrl . '/css/jquery-ui.min.css');
		Yii::app()->clientScript->registerScript('cm-add-addr', "
			var data = '" . $newAddresses . "';
			var newAddresses = data.split(', ');
			var ol = $('<ol></ol>');
			for (var i in newAddresses) {
				ol.append('<li><input type=\"checkbox\" value=\"' + newAddresses[i] + '\" name=\"CmAdd[box' + i + ']\" />&nbsp;<label for=\"CmAdd[box' + i + ']\" >' + newAddresses[i] + '</label></li>');
			}
			var form = $('<form method=\"post\" action=\"" . $this->createAbsoluteUrl('add') . "\"></form>').append(ol);
			var modal = $('<div id=\"modal\"></div>');
			modal.append('<h5>This address(es) not in you contact manager</h5>');
			modal.append(form);
			modal.dialog({
				autoOpen: false,
				width: 350,
				modal: true,
				title: 'Email successfully sent, but...',
				buttons: {
					'Add to contact manager': function(){
						var request = $.ajax({
							url: form.attr('action'),
							type: 'post',
							data: form.serialize(),
							async: false
						});
						request.done(function (response, textStatus, jqXHR){							
							console.log(response);
						});
						$(this).dialog('close');
					},
					'Skip': function(){
						$(this).dialog('close');
					}
				}
			});			
			modal.dialog('open');
		", CClientScript::POS_READY);
	}
?>
<div class="form">
<?php echo CHtml::beginForm(); ?>
 
    <?php echo CHtml::errorSummary($model); ?>
 
    <div class="row">
        <?php echo CHtml::activeLabel($model,'from'); ?>
        <?php echo CHtml::activeTextField($model,'from') ?>
    </div>
    <div class="row">
        <?php echo CHtml::activeLabel($model,'to'); ?>
        <?php echo CHtml::activeTextField($model, 'to', array('id' => 'toField')) ?>
    </div>
    <div class="row">
        <?php echo CHtml::activeLabel($model,'subject'); ?>
        <?php echo CHtml::activeTextField($model,'subject') ?>
    </div>
    <div class="row">
        <?php echo CHtml::activeLabel($model,'content'); ?>
        <?php echo CHtml::activeTextArea($model,'content') ?>
    </div>
 
    <div class="row submit">
        <?php echo CHtml::submitButton('Send'); ?>
    </div>
 
<?php echo CHtml::endForm(); ?>
<button onclick="var child = window.open('<?php echo $this->createAbsoluteUrl('pick'); ?>', 'cManager', 'status = 1, height = 600, width = 800, resizable = 0' ); child.localStorage.clear();">Use Contact Manager to enter Address(es)</button>
</div>
